"""
Text/epub_0010_0002.html

https://weread.qq.com/web/epub_0010_0002.html




https://weread.qq.com/web/reader/75432b50727d8270754e35c
k2a3327002582a38a4a932bf?


{
    "userVid": 42146813,
    "name": "热气球🎈",
    "gender": 1,
    "avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/xPjAuSXMic26mSVL9bunqtwxNO6cXMibWbRdHts7Sib1ibW8tFCR3BuwicQmztozLxXia9uxde8F8lj6XrZLJMDjCgyg/132",
    "isHide": 1,
    "medalInfo": {
        "id": "M4-0-50",
        "desc": "阅读书籍",
        "title": "阅读书籍",
        "levelIndex": 0
    },
    "signature": "",
    "location": "山东 聊城"
}


############
请求 URL:https://weread.qq.com/web/book/chapterInfos
请求方法:POST
data={
    "bookIds": [
        "41779824"
    ]
}

"""
import requests


def get_cookies():
    """ 功能：处理字符串形式的Cookie为字典形式 """
    cookies = {}
    cookie_string = 'wr_fp=3840720890; wr_gid=216628487; wr_vid=42146813; wr_skey=T0sbpCcT; wr_pf=0; wr_rt=web%40foOGPiVPqSqdzc~q8vk_AL; wr_localvid=594324c072831bfd594d158; wr_name=%E7%83%AD%E6%B0%94%E7%90%83%F0%9F%8E%88; wr_avatar=https%3A%2F%2Fthirdwx.qlogo.cn%2Fmmopen%2Fvi_32%2FxPjAuSXMic26mSVL9bunqtwxNO6cXMibWbRdHts7Sib1ibW8tFCR3BuwicQmztozLxXia9uxde8F8lj6XrZLJMDjCgyg%2F132; wr_gender=1'
    for kv in cookie_string.split('; '):
        key = kv.split('=')[0]
        value = kv.split('=')[1]
        cookies[key] = value
    # 此循环结束后，cookies为最终的字典
    return cookies


# post_url = 'https://weread.qq.com/web/book/chapterInfos'
# data = {"bookIds": ["41779824"]}
# url = 'https://weread.qq.com/web/shelf'
# headers = {
#     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36', }
#
# cookies = get_cookies()
# html = requests.post(url=post_url, headers=headers, cookies=cookies, data=data).text
# print(html)


get_url = 'https://weread.qq.com/web/reader/75432b50727d8270754e35c'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36', }
cookies = get_cookies()
html = requests.get(url=get_url, headers=headers, cookies=cookies).text
print(html)
